package cn.jbolt.ai.core.chain.node.flow.varset;

import cn.hutool.core.util.StrUtil;
import cn.jbolt.ai.core.chain.ChainContext;
import cn.jbolt.ai.core.chain.node.action.dbquery.DbQueryConfig;
import cn.jbolt.ai.core.chain.node.base.AppConfigConstant;
import cn.jbolt.ai.core.chain.node.base.BaseNode;
import cn.jbolt.ai.core.chain.node.provider.CommonNodeProvider;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Component
public class VarSetNodeProvider extends BaseNode implements CommonNodeProvider {
    private static final Logger logger = LoggerFactory.getLogger(VarSetNodeProvider.class);


    @Override
    public void provide(JsonNode nodeConfig, ChainContext context) {
        VarSetConfig varSetConfig = VarSetConfig.from(nodeConfig.get(AppConfigConstant.CONFIG_TYPE_VAR_SET));

        if (varSetConfig.getVars() != null) {
            varSetConfig.getVars().forEach(varSet -> {
                String inputField = varSet.get("name").asText();
                String value = varSet.get("value").asText();
                context.setAttr(inputField, Objects.equals(value, "null") ? null : value);
            });
        }

    }






}
